

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class ActionCanvas extends Canvas implements Runnable{ 
	
	static int w, h;
	static byte anchor=Graphics.TOP | Graphics.LEFT; 
	static final int MAX_GAME_SPEED=33;
	static int fps;	
	static int x=0;
	static Level lev = new Level();
	 Image img;
	 
	
	
	ActionCanvas(){
		setFullScreenMode(true);
		Tb.w = this.getWidth();
		Tb.h = this.getHeight();
		w = this.getWidth();
		h = this.getHeight();
		     
		
		
		new Thread(this).start(); //Kick-Off Game Loop
		
	}

	public void run(){
		try {
			while(true){ //Game Loop

				long startTime = System.currentTimeMillis();
				repaint(); //veranlassen, dass paint() erneut aufgerufen werden soll 
				//for (int i=0; i<999999; i++); //Bremse
				serviceRepaints();
				Thread.yield(); 				
				long executionTime = System.currentTimeMillis()-startTime;
	
				if (executionTime<MAX_GAME_SPEED){
					Thread.sleep(MAX_GAME_SPEED-(int)executionTime);
					fps=1000/MAX_GAME_SPEED;
				} else fps=(int) (1000/executionTime);
	
			}
		} catch (Exception e){}  
	}	
		 	
	public void paint(Graphics g){	
   if (!Tb.init) {
	   
   }
		Tb.Flush(g);
		lev.generateMap(1,g);

		//g.drawImage(img, Tb.w, Tb.h, Tb.anchor);
	  
      
      
      
		g.drawString("FPS: "+fps, 10,10, anchor);
		
		
		
	}	
}
	
